import request from '@/utils/request'
import { makeRequestJson } from '@/utils/common'

/**
 *
 * @param params 为一个json
 * {
 *    "method":"post/get",
 *    "url":"查询地址",
 *    "query":"查询参数json",
 *    "responseType":"responseType",
 * }
 * @returns {AxiosPromise}
 */
export function list(params) {
  const query = params.query
  const url = params.url
  const responseType = params.responseType
  const method = params.method

  for (const key in query) {
    if (query[key] === '') {
      query[key] = undefined
    }
  }

  console.log(query)
  return request(makeRequestJson(method, url, query, responseType))
}

/**
 *
 * @param params 为一个json
 * {
 *    "url":"查询地址",
 *    "data":"数据",
 *    "responseType":"responseType",
 * }
 * @returns {AxiosPromise}
 */
export function create(params) {
  return request(makeRequestJson(params.method, params.url, params.data))
}

/**
 *
 * @param params 为一个json
 * {
 *    "url":"查询地址",
 *    "data":"数据",
 *    "responseType":"responseType",
 * }
 * @returns {AxiosPromise}
 */
export function get(params) {
  return request(makeRequestJson(params.method, params.url, params.data))
}

export function update(params) {
  return request(makeRequestJson(params.method, params.url, params.data))
}
